{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Curve clipping (曲线裁剪)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "This method is used to crop curves (该方法用于裁剪曲线)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "import math\n",
    "\n",
    "\n",
    "# from mpl_toolkits.axes_grid1 import make_axes_locatable\n",
    "# from scipy import interpolate\n",
    "from pandas import set_option\n",
    "set_option(\"display.max_rows\", 15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 使用GPU训练时候，打开下面注释\n",
    "import os\n",
    "# os.environ['CUDA_VISIBLE_DEVICES']='0'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Set the type of curve to crop (设定要裁剪的曲线种类)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 定义要处理的常规测井资料\n",
    "# usual_log_names = [\"AC\",\"CNL\",\"DEN\",\"GR\",\"RD\",\"RS\"]\n",
    "# usual_log_names = [\"DT\",\"CNL\",\"DEN\",\"GR\",\"RD\",\"RS\"]#,\"DTXX\"]\n",
    "usual_log_names = [\"DTC\",\"DTS\"]\n",
    "\n",
    "# 定义是否要使用常规测井资料，True | False\n",
    "use_usual_log = True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Import raw csv data (原始数据导入)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "if use_usual_log == True:\n",
    "    data_path = 'data/usual_logs/'\n",
    "\n",
    "filename = 'GY1_R_0.1524m.csv'\n",
    "geo_lable = 'QSK'  # 整段； QSK Layer; QT Layer,\n",
    "element_logs_file = os.path.join(data_path, filename)\n",
    "# 读取A、B部分共有数据\n",
    "un_process = pd.read_csv(element_logs_file,engine='python',encoding='GBK')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Set the type of curve to crop  (设定裁剪测井曲线长度范围)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 起始长度和终止长度\n",
    "# 设定目标范围\n",
    "start_depth = 5617\n",
    "end_depth = 6092"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>DTC</th>\n",
       "      <th>DTS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5563.8877</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5564.0401</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5564.1925</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5564.3449</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5564.4973</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5564.6497</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5564.8021</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3511</th>\n",
       "      <td>6098.9641</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3512</th>\n",
       "      <td>6099.1165</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3513</th>\n",
       "      <td>6099.2689</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3514</th>\n",
       "      <td>6099.4213</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3515</th>\n",
       "      <td>6099.5737</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3516</th>\n",
       "      <td>6099.7261</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3517</th>\n",
       "      <td>6099.8785</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3518 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH      DTC      DTS\n",
       "0     5563.8877 -99999.0 -99999.0\n",
       "1     5564.0401 -99999.0 -99999.0\n",
       "2     5564.1925 -99999.0 -99999.0\n",
       "3     5564.3449 -99999.0 -99999.0\n",
       "4     5564.4973 -99999.0 -99999.0\n",
       "5     5564.6497 -99999.0 -99999.0\n",
       "6     5564.8021 -99999.0 -99999.0\n",
       "...         ...      ...      ...\n",
       "3511  6098.9641 -99999.0 -99999.0\n",
       "3512  6099.1165 -99999.0 -99999.0\n",
       "3513  6099.2689 -99999.0 -99999.0\n",
       "3514  6099.4213 -99999.0 -99999.0\n",
       "3515  6099.5737 -99999.0 -99999.0\n",
       "3516  6099.7261 -99999.0 -99999.0\n",
       "3517  6099.8785 -99999.0 -99999.0\n",
       "\n",
       "[3518 rows x 3 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "un_process"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>DTC</th>\n",
       "      <th>DTS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5563.8877</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5564.0401</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5564.1925</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5564.3449</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5564.4973</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5564.6497</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5564.8021</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3511</th>\n",
       "      <td>6098.9641</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3512</th>\n",
       "      <td>6099.1165</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3513</th>\n",
       "      <td>6099.2689</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3514</th>\n",
       "      <td>6099.4213</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3515</th>\n",
       "      <td>6099.5737</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3516</th>\n",
       "      <td>6099.7261</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3517</th>\n",
       "      <td>6099.8785</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3518 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH      DTC      DTS\n",
       "0     5563.8877 -99999.0 -99999.0\n",
       "1     5564.0401 -99999.0 -99999.0\n",
       "2     5564.1925 -99999.0 -99999.0\n",
       "3     5564.3449 -99999.0 -99999.0\n",
       "4     5564.4973 -99999.0 -99999.0\n",
       "5     5564.6497 -99999.0 -99999.0\n",
       "6     5564.8021 -99999.0 -99999.0\n",
       "...         ...      ...      ...\n",
       "3511  6098.9641 -99999.0 -99999.0\n",
       "3512  6099.1165 -99999.0 -99999.0\n",
       "3513  6099.2689 -99999.0 -99999.0\n",
       "3514  6099.4213 -99999.0 -99999.0\n",
       "3515  6099.5737 -99999.0 -99999.0\n",
       "3516  6099.7261 -99999.0 -99999.0\n",
       "3517  6099.8785 -99999.0 -99999.0\n",
       "\n",
       "[3518 rows x 3 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除NAN行,\n",
    "# un_process_YS = un_process.dropna(axis=0).drop_duplicates(subset='DEPTH', keep='last')\n",
    "# 删除重复列\n",
    "un_process_YS = un_process.dropna(axis=1).drop_duplicates(subset='DEPTH', keep='last')\n",
    "un_process_YS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3518, 3)\n"
     ]
    }
   ],
   "source": [
    "print(un_process_YS.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Determine whether the original data has the target curve (判断原始数据是否具备目标的曲线)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "process_YS_cols = (un_process_YS.columns[1:]).tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['DTC', 'DTS']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_YS_cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "object_cols: ['DTC', 'DTS']\n",
      "Corresponding Exactly!!!\n"
     ]
    }
   ],
   "source": [
    "\n",
    "object_cols = []\n",
    "if use_usual_log == True:\n",
    "    object_cols = usual_log_names\n",
    "else:\n",
    "    object_cols = element_names\n",
    "print('object_cols:',object_cols)\n",
    "if set(object_cols).issubset(set(process_YS_cols)):\n",
    "    if process_YS_cols == object_cols:\n",
    "        print(\"Corresponding Exactly!!!\")\n",
    "    else:\n",
    "        print(\"corresponding!!!\")\n",
    "else:\n",
    "    print(\"logs columns is incompatible!!!\")\n",
    "    missing_logs = [i for i in object_cols if (i not in process_YS_cols)]\n",
    "    print('missing_logs:',missing_logs)\n",
    "    exit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Crop(进行裁剪)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5563.8877</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5564.0401</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5564.1925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5564.3449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5564.4973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5564.6497</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5564.8021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3511</th>\n",
       "      <td>6098.9641</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3512</th>\n",
       "      <td>6099.1165</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3513</th>\n",
       "      <td>6099.2689</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3514</th>\n",
       "      <td>6099.4213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3515</th>\n",
       "      <td>6099.5737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3516</th>\n",
       "      <td>6099.7261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3517</th>\n",
       "      <td>6099.8785</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3518 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH\n",
       "0     5563.8877\n",
       "1     5564.0401\n",
       "2     5564.1925\n",
       "3     5564.3449\n",
       "4     5564.4973\n",
       "5     5564.6497\n",
       "6     5564.8021\n",
       "...         ...\n",
       "3511  6098.9641\n",
       "3512  6099.1165\n",
       "3513  6099.2689\n",
       "3514  6099.4213\n",
       "3515  6099.5737\n",
       "3516  6099.7261\n",
       "3517  6099.8785\n",
       "\n",
       "[3518 rows x 1 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "C_DEPTH = un_process_YS.loc[:,[\"DEPTH\"]]\n",
    "C_DEPTH"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>DTC</th>\n",
       "      <th>DTS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5563.8877</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5564.0401</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5564.1925</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5564.3449</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5564.4973</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5564.6497</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5564.8021</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3511</th>\n",
       "      <td>6098.9641</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3512</th>\n",
       "      <td>6099.1165</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3513</th>\n",
       "      <td>6099.2689</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3514</th>\n",
       "      <td>6099.4213</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3515</th>\n",
       "      <td>6099.5737</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3516</th>\n",
       "      <td>6099.7261</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3517</th>\n",
       "      <td>6099.8785</td>\n",
       "      <td>-99999.0</td>\n",
       "      <td>-99999.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3518 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH      DTC      DTS\n",
       "0     5563.8877 -99999.0 -99999.0\n",
       "1     5564.0401 -99999.0 -99999.0\n",
       "2     5564.1925 -99999.0 -99999.0\n",
       "3     5564.3449 -99999.0 -99999.0\n",
       "4     5564.4973 -99999.0 -99999.0\n",
       "5     5564.6497 -99999.0 -99999.0\n",
       "6     5564.8021 -99999.0 -99999.0\n",
       "...         ...      ...      ...\n",
       "3511  6098.9641 -99999.0 -99999.0\n",
       "3512  6099.1165 -99999.0 -99999.0\n",
       "3513  6099.2689 -99999.0 -99999.0\n",
       "3514  6099.4213 -99999.0 -99999.0\n",
       "3515  6099.5737 -99999.0 -99999.0\n",
       "3516  6099.7261 -99999.0 -99999.0\n",
       "3517  6099.8785 -99999.0 -99999.0\n",
       "\n",
       "[3518 rows x 3 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "un_process_YS.set_index([\"DEPTH\"], drop=False)\n",
    "un_process_YS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 判断起始长度和终止长度是否在原始测井曲线范围内\n",
    "# Determine whether the starting and ending lengths are within the range of the original logging curve\n",
    "if start_depth < min(C_DEPTH.values):\n",
    "    print(\"start depth is wrong!\")\n",
    "    exit()\n",
    "if end_depth > max(C_DEPTH.values):\n",
    "    print(\"end depth is wrong!\")\n",
    "    exit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "depth_range = []\n",
    "# numpy.where() 函数返回输入数组中满足给定条件的元素的索引。\n",
    "a = np.where(C_DEPTH.DEPTH >= start_depth)[0][0]\n",
    "b = np.where(C_DEPTH.DEPTH >= end_depth)[0][0]\n",
    "# if \n",
    "\n",
    "start_index = a\n",
    "end_index =  b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# a = np.where(C_DEPTH.DEPTH <= start_depth)[0][-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(349, 3466)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "start_index,end_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>DTC</th>\n",
       "      <th>DTS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>349</th>\n",
       "      <td>5617.0753</td>\n",
       "      <td>75.3691</td>\n",
       "      <td>155.1939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>5617.2277</td>\n",
       "      <td>74.9615</td>\n",
       "      <td>153.6787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>351</th>\n",
       "      <td>5617.3801</td>\n",
       "      <td>74.5912</td>\n",
       "      <td>151.0225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>352</th>\n",
       "      <td>5617.5325</td>\n",
       "      <td>73.8546</td>\n",
       "      <td>147.7337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>5617.6849</td>\n",
       "      <td>72.8347</td>\n",
       "      <td>145.1820</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>5617.8373</td>\n",
       "      <td>72.5753</td>\n",
       "      <td>144.4313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>355</th>\n",
       "      <td>5617.9897</td>\n",
       "      <td>73.4508</td>\n",
       "      <td>145.5181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3460</th>\n",
       "      <td>6091.1917</td>\n",
       "      <td>85.1627</td>\n",
       "      <td>169.4444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3461</th>\n",
       "      <td>6091.3441</td>\n",
       "      <td>85.5282</td>\n",
       "      <td>169.5480</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3462</th>\n",
       "      <td>6091.4965</td>\n",
       "      <td>86.9261</td>\n",
       "      <td>175.0535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3463</th>\n",
       "      <td>6091.6489</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3464</th>\n",
       "      <td>6091.8013</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3465</th>\n",
       "      <td>6091.9537</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3466</th>\n",
       "      <td>6092.1061</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>-99999.0000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3118 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH         DTC         DTS\n",
       "349   5617.0753     75.3691    155.1939\n",
       "350   5617.2277     74.9615    153.6787\n",
       "351   5617.3801     74.5912    151.0225\n",
       "352   5617.5325     73.8546    147.7337\n",
       "353   5617.6849     72.8347    145.1820\n",
       "354   5617.8373     72.5753    144.4313\n",
       "355   5617.9897     73.4508    145.5181\n",
       "...         ...         ...         ...\n",
       "3460  6091.1917     85.1627    169.4444\n",
       "3461  6091.3441     85.5282    169.5480\n",
       "3462  6091.4965     86.9261    175.0535\n",
       "3463  6091.6489 -99999.0000 -99999.0000\n",
       "3464  6091.8013 -99999.0000 -99999.0000\n",
       "3465  6091.9537 -99999.0000 -99999.0000\n",
       "3466  6092.1061 -99999.0000 -99999.0000\n",
       "\n",
       "[3118 rows x 3 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "C_element = un_process_YS.loc[start_index : end_index]\n",
    "C_element"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Saving data to csv(结果写入csv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import datetime\n",
    "def tid_maker():\n",
    "    return '{0:%Y-%m%d-%H%M}'.format(datetime.datetime.now())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "高102_R_0.1524m\n"
     ]
    }
   ],
   "source": [
    "csvfile_name = filename.split(\".csv\")[0] #'TT1-4500m-5070m_R_0.1524.csv'\n",
    "print(csvfile_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# C_element.to_csv(data_path + csvfile_name + '_new_'+ str(start_depth) + 'm-'+str(end_depth) + \"m_\" + tid_maker()+ '.csv',mode='w',index = False,header=True)\n",
    "C_element.to_csv(data_path + csvfile_name + '_' + geo_lable + '_'+ str(start_depth) + 'm-'+str(end_depth) + \"m\" + '.csv',mode='w',index = False,header=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finished!!\n",
      "data/usual_logs/高102_R_0.1524m_整段_5617m-6092m.csv\n"
     ]
    }
   ],
   "source": [
    "print(\"Finished!!\")\n",
    "# print(data_path + csvfile_name + '_new_'+ str(start_depth) + 'm-'+str(end_depth) + \"m_\" + tid_maker()+ '.csv')\n",
    "print(data_path + csvfile_name + '_' + geo_lable + '_'+ str(start_depth) + 'm-'+str(end_depth) + \"m\" + '.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020-0522-1715\n"
     ]
    }
   ],
   "source": [
    "print(tid_maker())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "256px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}